package com.ccit.zhxy.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ccit.zhxy.pojo.Teacher;
import com.ccit.zhxy.service.TeacherService;
import com.ccit.zhxy.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 鹏少
 * @Date 2023/12/26
 * @Date 14:08
 */
@Api(tags = "老师控制器")
@RestController
@RequestMapping("/sms/teacherController")
public class TeacherController {

    @Autowired
    private TeacherService teacherService;


    @ApiOperation("获取教师信息,分页带条件")
    @GetMapping("/getTeachers/{pageNo}/{pageSize}")
    public Result getTeachers(
            @ApiParam("pageNo") @PathVariable Integer pageNo,
            @ApiParam("pageSize") @PathVariable Integer pageSize,
            String name,
            String clazzName
    ){
        Page<Teacher> page = new Page<>(pageNo, pageSize);
        page=teacherService.lambdaQuery().eq(clazzName!=null, Teacher::getClazzName,clazzName)
                .like(name!=null,Teacher::getName,name).orderByAsc(Teacher::getId).page(page);
        return Result.ok(page);


    }

    @ApiOperation("添加和修改教师信息")
    @PostMapping("/saveOrUpdateTeacher")
    public Result saveOrUpdateTeacher(
            @RequestBody Teacher teacher
    ){
        teacherService.saveOrUpdate(teacher);
        return Result.ok();
    }


    @ApiOperation("删除一个或者多个教师信息")
    @DeleteMapping("/deleteTeacher")
    public Result deleteTeacher(
            @RequestBody List<Integer> ids
    ){
        teacherService.removeByIds(ids);
        return Result.ok();
    }

}
